// 请求封装
// 定义一个基础路径
const baseURL = 'http://nocat.life:3012';
// 封装请求的函数
const request = async (url, method, data, isLoading = true) => {
	// 请求结果中 加载的loading
	// 先在 参数上面 设置一个默认值 不传参就是默认值 
	if (isLoading) {
		uni.showLoading({
			title: '加载中'
		});
	}
	const res = await uni.request({
		url: baseURL + url,
		method,
		data,
		timeout: 3000,
		// 给每一个请求加一个请求头
		header: {
			Authorization: uni.getStorageSync(
				'user_token'
			) //获取本地存储的token
		}
	})
	// 隐藏加载中
	uni.hideLoading()
	// 将请求结果返回
	return res.data
}

// 请求类型的封装
export const httpGet = (url, data, isLoading) => {
	return request(url, 'GET', data, isLoading)
}
export const httpPost = (url, data, isLoading) => {
	return request(url, 'POST', data, isLoading)
}
export const httpPut = (url, data, isLoading) => {
	return request(url, 'PUT', data, isLoading)
}
export const httpDelete = (url, data, isLoading) => {
	return request(url, 'DELETE', data, isLoading)
}